<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/vue.js"></script>
    <style>
        .mydiv{
            width: 400px;
            height: 220px;
            background-color: gray;
        }
        .red{
            background-color: red;
        }
        .yellow{
            background-color: yellow;
        }
        .green{
            background-color: green;
        }
        .mywidth{
            width: 450px;
        }

    </style>
</head>
<body>

    <div id="app">
        <div class="mydiv" v-bind:class="{red:temp}"></div>
        <hr />
        <div class="mydiv" :class="myClassStyle"></div>
        <div class="mydiv"></div>

        <button type="button" @click="temp=!temp">点我</button>
    </div>

</body>
<script>
    new Vue({
        el:"#app",
        data:{
            temp:false
        },
        computed:{
          myClassStyle:function () {
            return{
                red:this.temp,
                mywidth:this.temp
            }
          }
        }

    })
</script>
</html>